Component({
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    phone: {
      type: String,
      value: ''
    },
    avatarUrl: {
      type: String,
      value: ''
    }
  },
  methods: {
    //阻止事件冒泡
    preventTap: function() {
    },
    //隐藏登陆
    hideModal: function() {
      this.setData({
        show: false
      });
    },
    //切换手机
    switchPhone() {
      wx.navigateTo({
        url: '/pages/login/login'
      });
    },
    //登出
    logout() {
      wx.cloud.callFunction({
        name: 'logout',
        success: res => {
          if (res.result.success) {
            wx.removeStorageSync('phone');
            wx.removeStorageSync('openid');
            wx.showToast({
              title: '退出登录成功',
              icon: 'success',
              duration: 2000
            });
            wx.reLaunch({
              url: '/pages/market/market'
            });
          } else {
            wx.showToast({
              title: '退出登录失败',
              icon: 'error',
              duration: 2000
            });
          }
        },
        fail: err => {
          wx.showToast({
            title: '退出登录失败',
            icon: 'error',
            duration: 2000
          });
        }
      });
    }
  }
});
